//
//  NewMissionBusinessNumberProcessView.m
//  HCNewGoldFinger
//
//  Created by 刘琛 on 2018/3/30.
//  Copyright © 2018年 zjhcsoftios. All rights reserved.
//

#import "NewMissionBusinessNumberProcessView.h"
#import "NewMissionBusinessNumberProcessModel.h"
#import "ZSBNewOrdorDetailCell.h"
#import "NSBundle+AssociatedBundle.h"
#import "NetworkAddress.h"
#import "iSeeNetworkRequest.h"
#import <MJExtension/MJExtension.h>
#import "SVProgressHUD.h"

@interface NewMissionBusinessNumberProcessView()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSString *orderId;

@property (nonatomic, strong) NSString *businessNumber;

@property (nonatomic, strong) NSMutableArray *dataList;

@end

@implementation NewMissionBusinessNumberProcessView

static NSString *NewMissionBusinessNumberProcessViewCellIdentify = @"NewMissionBusinessNumberProcessViewCellIdentify";

- (void)awakeFromNib {
    [super awakeFromNib];
    _dataList = [NSMutableArray array];
    
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 80;
    [self.tableView registerNib:[UINib nibWithNibName:@"ZSBNewOrdorDetailCell" bundle:nil] forCellReuseIdentifier:NewMissionBusinessNumberProcessViewCellIdentify];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}


+ (void)showBusinessNumberProcessView:(UIView *)view orderId:(NSString *)orderId BusinessNumber:(NSString *)businessNumber {
    NewMissionBusinessNumberProcessView *processView = [[NSBundle bundleWithBundleName:@"NewMarketLib" podName:@"NewMarketLib"] loadNibNamed:@"NewMissionBusinessNumberProcessView" owner:self options:nil].lastObject;
    processView.frame = CGRectMake(0, 0, kScreenWidth, kScreenHeight);
    processView.orderId = orderId;
    processView.businessNumber = businessNumber;
    [processView yewuhaoma];
    [view addSubview:processView];
    
}



//业务号码活动信息
- (void)yewuhaoma{

    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    if (_orderId) {
        [params setObject:_orderId forKey:@"orderId"];
    }
    [params setObject:_businessNumber forKey:@"ywhm"];
    
    [iSeeNetworkRequest getWithHeaderUrl:kFormat(@"%@%@",NMarketMainUrl,ZPHChuodongxinxi) params:params success:^(id object) {
        [self.dataList addObjectsFromArray:[NewMissionBusinessNumberProcessModel mj_objectArrayWithKeyValuesArray:object[@"body"][@"detailInfoList"]]];
        
        [self.tableView reloadData];
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
    }];
    
}


#pragma mark table

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ZSBNewOrdorDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:NewMissionBusinessNumberProcessViewCellIdentify forIndexPath:indexPath];
    cell.businessModel = _dataList[indexPath.row];
    if (indexPath.row == 0) {
        cell.isFirstCell = YES;
        if (_dataList.count == 1) {
            cell.isLastCell = YES;
        }
    }else if (indexPath.row == _dataList.count - 1) {
        cell.isLastCell = YES;
    }else {
        cell.isMiddleCell = YES;
    }
    return cell;
}


#pragma mark 按钮点击事件
- (IBAction)cannelButtomAction:(UIButton *)sender {
    
    [self removeFromSuperview];
}



@end
